<?php
require_once('include/lsamp_curl.php');
require_once('config.php');
$vs_manager = new lsamp_cURL(TRUE,'cookies.txt','gzip','',$webmin_vs_url);
if(!isset($_POST['dom'])){
	$result = $vs_manager->get($webmin_vs_url, $errno, $error);
	if($errno !== 0){
		die("Error: " . $error);
	}
	preg_match_all('/<a\shref=\'edit_domain.cgi\?dom=([^>]+)\'>([^<]+)<\/a><\/td>\n<td valign=top>([^<]+)<\/td>/', $result, $matches);
	$doms = array();
	$i = 0;
	for(;$i<count($matches[3]);$i++){
		if($matches[3][$i] == $_GET['owner']){
			$doms[$matches[2][$i]] = $matches[1][$i];
		}
	}
	$form = '<form action="delete_vs.php" method="post">';
	$table = '<table align="center">';
	$table .= '<tr><td>Select an domain to delete </td><td><select name="dom">';
	foreach(array_keys($doms) as $dom_url){
		$table .= '<option value="' . $doms[$dom_url] . '">' . $dom_url ;
	}
	$table .= '</select></td></tr>';
	$table .= '<tr><td colspan="2" align="right"><input type="checkbox" name="only" value="1"  id="only_1" >'
	. '<label for="only_1">Only remove server from Virtualmin\'s control, and leave website, users and databases untouched</label></td></tr>';

	$table .= '<tr><td colspan="2" align="center"><input type="submit" name="confirm" value="Yes, Delete It"></td></tr>';
	$form .= $table;
	$form .= '</form>';
	echo $form;
}else{
	$delete_data = http_build_query($_POST);
	$result = $vs_manager->get($webmin_vs_delete_url . "?" . $delete_data, $errno, $error);
	if($errno !== 0){
		die("Error: " . $error);
	}
	echo $result;
}
